package io.rehuo.modules.app.controller;

import io.rehuo.common.utils.R;
import io.rehuo.modules.app.annotation.Login;
import io.rehuo.modules.app.annotation.LoginUser;
import io.rehuo.modules.app.entity.UserBankEntity;
import io.rehuo.modules.app.entity.UserEntity;
import io.rehuo.modules.app.service.UserBankService;
import io.rehuo.modules.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/user")
@Api("用户接口")
public class AppUserController {

    @Autowired
    private UserService service;

    @Autowired
    private UserBankService userBankService;

    @Login
    @GetMapping("userInfo")
    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    public R userInfo(@LoginUser UserEntity user) {
        return R.ok("user", user);
    }

    @Login
    @GetMapping("getUserBank")
    @ApiOperation(value = "获取用户银行卡信息", notes = "获取用户银行卡信息")
    public R getUserBank(@LoginUser UserEntity user){
        return R.ok("userBank",userBankService.getByUserId(user.getUserId()));
    }

    @Login
    @PostMapping("saveUserBank")
    public R saveUserBank(@LoginUser UserEntity userEntity, @RequestBody UserBankEntity userbank){
        userBankService.saveUserBank(userEntity,userbank);
        return R.ok();
    }

    @Login
    @PostMapping("updateUserOperator")
    public R updateUserOperator(@LoginUser UserEntity userEntity){
        service.updateUserOperator(userEntity);
        return R.ok();
    }

}
